package chapter2;

/**
 * Created by LinGer on 2019/6/17
 */
public class MyThread extends Thread {

    private int ticket = 10;

    @Override
    public void run() {
        for (int i = 0; i < 20; i++) {
            if(this.ticket > 0){
                //this.getName()是调用的Thread中的getName方法
                System.out.println(this.getName() + "卖票: ticket" + this.ticket--);
            }
        }
    }

    public static void main(String[] args) {
        MyThread thread1 = new MyThread();
        MyThread thread2 = new MyThread();
        MyThread thread3 = new MyThread();

        thread1.start();
        thread2.start();
        thread3.start();
    }
}
